(function(angular) {
	"use strict";
	angular.module("fs.waf").factory("txnService", txnService);
	txnService.$inject = [ "$q", "ajaxServiceFactory" ];
	function txnService($q, ajaxServiceFactory) {
		
		function getLayout(packageName, packageSuffix, readonly, parmCat, prodType, prodSubtype) {
			var ajaxServices = ajaxServiceFactory.buildAjaxService({
				getTxnLayout : {
					url : "do/cls/txn/layout",
					method : "post"
				}
			}), defer = $q.defer();
			var params = {
				packageName : packageName,
				packageSuffix : packageSuffix,
				readonly : readonly,
				parmCat : parmCat,
				parmSubcat : []
			};
			if(!prodType && !prodSubtype){
				params.parmSubcat.push("*");
			}
			if(prodType){
				params.parmSubcat.push("PRODTYPE-" + prodType);
			}
			if(prodSubtype){
				params.parmSubcat.push("PRODSUBTYPE-" + prodSubtype);
			}
			ajaxServices.getTxnLayout(params).then(function(response) {
				defer.resolve(response.data);
			}, angular.noop);
			return defer.promise;
		}
		/**
		 * param : [{
		 * 	parmCat : "",
		 * 	parmSubcat : [],
		 * 	readonly : true
		 * }]
		 */
		function getLayout2(packageName, packageSuffix, param) {
			var ajaxServices = ajaxServiceFactory.buildAjaxService({
				getTxnLayout : {
					url : "do/cls/txn/layout2",
					method : "post"
				}
			}), defer = $q.defer();
			var params = {
				packageName : packageName,
				packageSuffix : packageSuffix,
				param : param
			};
			ajaxServices.getTxnLayout(params).then(function(response) {
				defer.resolve(response.data);
			}, angular.noop);
			return defer.promise;
		}

		function deleteDynaparm(gridConfigs) {
			if (gridConfigs) {
				angular.forEach(gridConfigs, function(gridConfig, key) {
					if (gridConfig.dynamicParameter) {
						delete gridConfigs[key];
					}
				});
			}
		}


		return {
			getLayout : getLayout,
			deleteDynaparm : deleteDynaparm
		};
	}
})(angular);